home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
news
/
readers
/
skim-0.8
/
skim-0
/
skim-0.8.4
/
SetTest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-18
|
2KB
|
87 lines
/*
* NAME
* SetTest.c
* DESCRIPTION
* Test the Set class. Run this test by typing 'make test' in the source
* directory of skim.
* COPYRIGHT
* Copyright (C) 1996 Rene W.J. Pijlman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* VERSION
* $Header: /home/rene/sys/CVS_MasterSourceRepository/skim/SetTest.c,v 1.3 1996/02/18 11:40:23 rene Exp $
* Distributed with Skim version 0.8.4.
*/
#include "Set.h"
#include "StandardIO.h"
#include "MemAlloc.h"
#include <assert.h>
#include <string.h>
/* assert()'s must be in effect in this file. */
#ifdef NDEBUG
# undef NDEBUG
#endif
static void TestCreation( Set * Set1, Set * Set2 )
{
SetDestroy( SetCreate( (SetElementCompareFunction)abort,
(SetElementDestroyFunction)abort ) );
*Set1 = SetCreate( (SetElementCompareFunction)strcmp, MemFree );
*Set2 = SetCreate( (SetElementCompareFunction)strcasecmp, MemFree );
assert( SetNumberOfElements(*Set1) == 0 );
assert( SetNumberOfElements(*Set2) == 0 );
}
static void TestFind( Set Set1, Set Set2 )
{
assert( SetNumberOfElements(Set1) == 0 );
assert( SetNumberOfElements(Set2) == 0 );
SetAddElement( Set1, MemNewString("Aaa") );
SetAddElement( Set2, MemNewString("Bbb") );
assert( SetNumberOfElements(Set1) == 1 );
assert( SetNumberOfElements(Set2) == 1 );
SetFindElement( Set1, "aaa" );
SetFindElement( Set2, "bbb" );
assert( !SetElementExists(Set1) );
assert( SetElementExists(Set2) );
assert( !strcmp("Bbb", (char *)SetGetElement(Set2)) );
}
int main( void )
{
Set Set1;
Set Set2;
TestCreation( &Set1, &Set2 );
TestFind( Set1, Set2 );
SetDestroy( Set1 );
SetDestroy( Set2 );
SIOPrintf( StandardOutput, "OK\n" );
return EXIT_SUCCESS;
}